package utiles;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class HbaseUtils {
    static Table table = null;
    static Connection conn = null;
    static{
        try {
            Configuration conf = HBaseConfiguration.create();
            //指定zk的地址
            conf.set("hbase.zookeeper.quorum", "uplooking03:2181,uplooking04:2181,uplooking05:2181");
            conn = ConnectionFactory.createConnection(conf);
            table = conn.getTable(TableName.valueOf("ns1:t1"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void save(String rowkey,String key,String value) throws IOException {
        Put put = new Put(Bytes.toBytes(rowkey));
        put.addColumn(Bytes.toBytes("f1"),Bytes.toBytes(key),Bytes.toBytes(value));
        table.put(put);
    }
}
